<template>
  <div>
    <van-form @submit="onSubmit">
        <van-field
            v-model="userdata.email"
            name="email"
            label="邮箱"
            placeholder="邮箱"
            :rules="[{ required: true, message: '请填写邮箱' }]"
        />
        <van-field
            v-model="userdata.password"
            name="password"
            label="密码"
            :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px;">
            <van-button round block type="info" native-type="submit">登录</van-button>
        </div>
    </van-form>
  </div>
</template>

<script>
import {login} from "@/api"
export default {
  data(){
    return {
      userdata:{
        email:"",
        password:''
      }
    }
  },
  methods:{
    onSubmit(){
      login(this.userdata).then(res => {
        window.localStorage.setItem('token',res.data.token);
        this.$router.push('/home');
      })
    }
  }
}
</script>

<style>

</style>